import { ECSSceneCmp } from "../../lib/kgame/ecs/ECSSceneCmp";
import { Cls } from "../../lib/kgame/util/Defined";
import { IRecyclePoolObj, RecyclePool } from "../../lib/kgame/util/Pool";

/**
 * 对象池管理
 */
export default class SCmpPoolMgr extends ECSSceneCmp {

    private _recyclePoolMap = new Map<any, RecyclePool<any>>();

    /**
     * 获取对应类的循环对象池
     * @param cls 
     */
    getRecyclePool<T extends IRecyclePoolObj>(cls: Cls<T>) {
        if (!this._recyclePoolMap.has(cls)) {
            this._recyclePoolMap.set(cls, new RecyclePool(cls));
        }
        return this._recyclePoolMap.get(cls) as RecyclePool<T>;
    }

}